#include "inventorybutton.h"
#include "gfxitems/gfxUnit.h"
#include "gfxitems/gfxTowerBeam.h"
#include <QPainter>
#include <QDebug>

InventoryButton::InventoryButton(const quint32 id, QWidget *parent) :
   QPushButton(parent),
   mID(id),
   mCount(1),
   mIconScale(1.0)
{
}


void InventoryButton::paintEvent(QPaintEvent *event)
{
   QPushButton::paintEvent(event);

   QPainter painter(this);
   painter.translate(width()/2, height()/2);

   qreal drawScale = 1.0;
   if (isChecked())
      drawScale = mIconScale;

   if (mStats.type == ENTITY_UNIT)
   {
      GFXUnit::doPaint(mStats.color, mStats.size, mStats.kind, mCount, painter, drawScale);
   }
   else
   {
      switch (mStats.kind)
      {
      default:
      case TOWER_BEAM:
         GFXTowerBeam::doPaint(mStats.color, mStats.size, false, false, painter, drawScale);
         break;
      }
   }
}


void InventoryButton::setEntityStats(const EntityBaseStats &stats) { mStats = stats; update(); }
void InventoryButton::setColor(const QColor &color) { mStats.color = color.rgb(); }
EntityBaseStats InventoryButton::entityStats() { return mStats; }
void InventoryButton::setID(const quint32 id) { mID = id; }
quint32 InventoryButton::id() { return mID; }
void InventoryButton::setCount(const quint32 count) { mCount = count; update(); }
quint32 InventoryButton::count() { return mCount; }
void InventoryButton::setIconScale(const qreal scale) { mIconScale = scale; }
